package com.jk.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jk.dto.SysMenu;
import com.jk.dto.TemUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description 添加描述
 * @LastChangeDate 2025/3/16 20:54
 * @Version v1.0
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenu> {
    /**
     * @description: 通过当前用户id获得当前的登录人的菜单集合
     * @param: [tbUser, l]
     * @return: java.util.List<com.jk.dto.sysMenu>
     * @author yzf
     * @date: 2025/3/9 19:49
     */
    @Select("   select m.* from sys_user_role ur\n" +
            "      left join sys_role_menu rm on ur.role_id = rm.role_id\n" +
            "      left join sys_menu m on rm.menu_id =m.menu_id where ur.user_id =#{temUser.id}\n" +
            "      and m.parent_id =#{parentId}\n" +
            "      and m.menu_type in(\"M\",\"C\")")
    List<SysMenu> findMenuListByUserId(@Param("temUser") TemUser temUser, @Param("parentId") Long parentId);

    /**
     * @description: 通过用户id获得权限集合
     * @param: [id]
     * @return: java.util.List<java.lang.String>
     * @author yzf
     * @date: 2025/3/9 20:42
     */
    @Select(" select DISTINCT m.perms from sys_user_role ur\n" +
            "        join sys_role_menu rm on ur.role_id = rm.role_id\n" +
            "        join sys_menu m on rm.menu_id = m.menu_id where ur.id = #{id} and m.perms != ''")
    List<String> selectPermsByUserId(Integer id);
}
